<?php
namespace app\modules\cn\models;

use app\libs\Pager;
use yii\db\ActiveRecord;

class QuestionRemarks extends ActiveRecord
{

    public static function tableName()
    {
        return '{{%mock_question_remarks}}';
    }

    public static function getRemarks($pid)
    {
        $uid = \Yii::$app->session->get('uid');
        $contentId = self::getAllContentId($pid);
        $data = self::find()->asArray()->where('content_id in (' . $contentId . ') and uid=' . $uid)->all();
        return $data;
    }

    public static function getAllContentId($pid)
    {
        $pidsArray = explode(',', $pid);
        static $data = array();
        foreach ($pidsArray as $key => $val) {
            $name = ExerciseList::find()->asArray()->select(['content_id', 'pid', 'name', 'cate_id'])->where("content_id=$val")->orderBy('content_id asc')->one();
            $pids = ExerciseList::find()->asArray()->select(['content_id', 'pid', 'name', 'cate_id'])->where('cate_id=' . $name['cate_id'] . ' and name="' . $name['name'] . '"')->orderBy('content_id asc')->all();
            $data = array_merge($data, $pids);
        }
        $contentId = implode(',', array_column($data, 'content_id'));
        return $contentId;
    }


}
